class AIMelee extends AI{
	
	public function AIMelee(selectedEnemy:EnemyCharacter, playerList:Array){
		super(selectedEnemy, playerList);
		
		_detectFlankRadius = selectedEnemy.getMoveRadius() + 5; 
		
		checkDistanceRange();		
	}
	public function getCoverTile(mapReference){
		var tile:Tile;
		
		if(_closestDistance <= _selectedEnemy.getEngageRadius()){			
			tile = getClosestTile(mapReference);
		}else{
			tile = getCoverTile(1, mapReference);
		}
		
		return tile;
	}
	public function getForwardCoverTile(mapReference){
		var tile:Tile;
		Debug.Log("Check distance: "+_closestDistance+" | "+_selectedEnemy.getEngageRadius());
		if(_closestDistance <= _selectedEnemy.getEngageRadius()){			
			tile = getClosestTile(mapReference);
		}else{
			tile = getForwardCoverTile(1, mapReference);
		}
		
		return tile;
	}
	private function getClosestTile(mapReference:Map):Tile{
		Debug.Log("Closest Tile");
		mapReference.checkRangeFrom(_selectedEnemy.getCoord(), _selectedEnemy.getMoveRadius());
		var tiles:Array = mapReference.getMoveRadiusTiles(_selectedEnemy.getCoord(), _selectedEnemy.getMoveRadius());
		var currentDistance;
		var closestCover:Tile;
		
		for(var i:int = 0; i<tiles.length; i++){
			currentDistance = Vector2.Distance(tiles[i].getCoord(), _closestPlayer.getCoord());			
			if(currentDistance < _closestDistance){
				//Debug.Log("Closest Covers: "+closestCover);
				_closestDistance = currentDistance;
				closestCover = tiles[i];
			}
		}
		
		return closestCover;
	}	
}